﻿#pragma once
#include <io.h>
#include <map>
#include <string>
#include <vector>

#define MAX_PATH_LEN 300
//#define PRINT_FILE_INFO

template <typename T>
std::vector<std::vector<T>> splitVector(std::vector<T> v, unsigned int divide)
{
    std::vector<std::vector<T>> result;
    auto total = v.size();
    auto quotient = total / divide;
    auto remainder = total % divide;
    auto index_remain = 0;
    auto add = 0;

    typename std::vector<T>::iterator curPtr = v.begin(), end;
    for (int i = 0; i < divide; i++)
    {
        add = 0;
        if (index_remain < remainder)
        {
            index_remain++;
            add = 1;
        }

        end = curPtr + quotient + add;
        result.push_back(std::vector<T>(curPtr, end));
        curPtr = end;
    }

    return result;
}

class FileTool
{
public:
    static void listFiles(const char *dir, const char *suffix, std::vector<_finddata_t> &files, int countWant = 0);
    static void listFilesW(const wchar_t *dir, const wchar_t *suffix, std::vector<_wfinddata64i32_t> &files, int countWant = 0);
    static void listFileArray(const char *dir, const char *suffix, std::map<std::string, _finddata_t> &files, size_t want_size, int countWant = 0);
    static size_t GetFileCount(const char *dir, const char *suffix);
    static int createDirectory(const std::wstring &directoryPath);
    static bool createDirectoriesA(const std::string &directories);
    static bool createDirectoriesW(const std::wstring &directories);
    static int64_t getFileSizeA(const std::string &path);
    static int64_t getFileSize(const std::wstring &path);
    static bool getKeyFileNameW(const std::wstring &filename, std::wstring &result);
    static bool getKeyFileName(const std::string &filename, std::string &result);
    static void WriteContent2TextFile(const std::string &filePath, const std::string &content);
    static void WriteContent2TextFileW(const std::wstring &filePath, const std::wstring &content);
    static bool waitFolderChange(std::wstring targetFolder);
    static bool getPart1FileName(const std::string &filename, std::string &result, char separator = '_');
    static bool CheckPathValid(std::wstring path, bool CreateIt = true);
    static bool CheckPathValidA(std::string path, bool CreateIt = true);
};
